package com.li.puzzle.viewpagerindicator;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;

import com.li.puzzle.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ViewPagerActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private ViewPagerIndicator mViewPagerIndicator;
    private List<String> mTitles;
    private List<Fragment> mFragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_view_pager);
        initView();
        initData();

    }

    private void initData() {
        mTitles = Arrays.asList("TEST1", "TEST2", "TEST3","TET4","TEST5","TEST6");
        mFragments=new ArrayList<>();
        mViewPagerIndicator.setTitles(mTitles);
        mViewPagerIndicator.setViewPager(mViewPager);

        for (String title : mTitles) {
            FragmentIndicator fragmentIndicator=FragmentIndicator.newInstance(title);
            mFragments.add(fragmentIndicator);
        }
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }

            @Override
            public int getCount() {
                return mFragments.size();
            }
        });
    }

    private void initView() {

        mViewPager = (ViewPager) findViewById(R.id.view_pager);
        mViewPagerIndicator = (ViewPagerIndicator) findViewById(R.id.vp_indicator);
    }


}
